//
//  WindStrengthView.swift
//  xgwjinterconnection
//
//  Created by WangWeiShuo on 2025/8/20.
//

import SwiftUI

struct WindStrengthView: View {
    // 信号强度值 (1-6)
        var strength: Int
        
        // 信号条的颜色
        var activeColor: Color = .green
        var inactiveColor: Color = .gray
        
        var body: some View {
            HStack(alignment: .bottom,spacing: 10) {
                // 第一根信号条（最短）
                SignalBar(
                    height: 8,
                    isActive: strength >= 1,
                    activeColor: activeColor,
                    inactiveColor: inactiveColor
                )
                
                // 第二根信号条
                SignalBar(
                    height: 16,
                    isActive: strength >= 2,
                    activeColor: activeColor,
                    inactiveColor: inactiveColor
                )
                
                // 第三根信号条
                SignalBar(
                    height: 24,
                    isActive: strength >= 3,
                    activeColor: activeColor,
                    inactiveColor: inactiveColor
                )
                
                // 第四根信号条
                SignalBar(
                    height: 32,
                    isActive: strength >= 4,
                    activeColor: activeColor,
                    inactiveColor: inactiveColor
                )
                
                // 第五根信号条
                SignalBar(
                    height: 40,
                    isActive: strength >= 5,
                    activeColor: activeColor,
                    inactiveColor: inactiveColor
                )
                
                // 第六根信号条（最长）
                SignalBar(
                    height: 48,
                    isActive: strength >= 6,
                    activeColor: activeColor,
                    inactiveColor: inactiveColor
                )
            }
            .alignmentGuide(.bottom) { $0[.bottom] }
        }
}

// 单个信号条视图
struct SignalBar: View {
    var height: CGFloat
    var isActive: Bool
    var activeColor: Color
    var inactiveColor: Color
    
    var body: some View {
        RoundedRectangle(cornerRadius: 1)
            .fill(isActive ? activeColor : inactiveColor)
            .frame(width: 12, height: height)
            .alignmentGuide(.bottom) { $0[.bottom] }
    }
}

#Preview {
    WindStrengthView(strength: 3)
}
